// pages/exam-type/exam-type.js
const app = getApp();
Page({
  data: {
    // options: [{
    //     text: '单选题',
    //     icon: 1
    //   },
    //   {
    //     text: '多选题',
    //     icon: 2
    //   },
    //   {
    //     text: '判断题',
    //     icon: 3
    //   }
    // ],
    currentOption: 0
  },
  onLoad() {
    // options type 1随机练习 3我的错题
    this.category_id = app.globalData.category.id;
    this.loadData();
  },
  loadData() {
    const that = this;
    app.request('/api/question/type').then(res => {
      console.log(res);
      that.setData({
        options: res.data.data
      });
    }).catch(err => {
      console.error(err);
    })
  },
  selectOption: function (e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      currentOption: index
    });
  },
  confirmSelection: function () {
    const selectedOption = this.data.options[this.data.currentOption];
    app.globalData.exam1Params = {
      category_id: this.category_id,
      type_id: selectedOption.id
    };
    app.globalData.exam1Title = selectedOption.name;
    app.globalData.exam1ViewMode = false;
    app.globalData.exam1ParamsNeedLoad = true;
    wx.navigateTo({
      url: '/pages/exam/exam',
    });
  }
});